#pragma once

#include "condition.h"
#include "action.h"


namespace BAA
{

	class Action_Defend_Seperate:public Action
	{
	public:


		Action_Defend_Seperate():Action("defend_seperate")
		{

		}


		virtual void Initialize(Role * roleParent, AgentPointerMap * targets)
		{
			Action::Initialize(roleParent, targets);
			mRange.y = -5.0f;
			mRange.y = 5.0f;

			mAngerFactor = 0.49f;
			mFearFactor = 0.5f;
			mHonorFactor = 0.6f;



			mPostcondition->push_back("defend");

			mPreconditions = new Conditions();

			AddConsequence("defend", 0.4f);
			AddConsequence("loudness", 0.1f);

		}

		virtual void PrepareConditions()
		{
			// nothing to do to run.
		}

		virtual void ApplyActionToInternalSate()
		{
			// reduce need for social contact
			RoleParent()->Self()->Properties()->mHonor->ModifyValue(-0.1f);
		}

		virtual float CalculateStateUtility()
		{
			AgentProperties * properties = mRoleParent->Self()->Properties();

			// this could be a condition rather then calculated during the utility
			Emotion * anger = (*mRoleParent->Emotions())["anger"];
			Emotion * fear =  (*mRoleParent->Emotions())["fear"];

			if(anger == NULL || fear == NULL)
				return 0.0f;


			// average out anger
			float angerVal = (properties->mAnger->GetValue() + anger->GetValue())/ 2.0f;
			


			// Talk to your friend when your not angry with them
			float emotionUtility = (1- abs(mAngerFactor - angerVal))- (1-abs(mFearFactor - fear->GetValue()));


			float personalityUtility = (1- abs( mHonorFactor - properties->mHonor->Desire()));
			float utility = emotionUtility + personalityUtility;

			return MathHelper::clamp(&mRange,emotionUtility + (0.5f)*personalityUtility);
		}






		~Action_Defend_Seperate()
		{

		}

	protected:
		// any members

		Vector2 mRange;

		float mAngerFactor;
		float mFearFactor;
		float mHonorFactor;
	};// end class
}// end namespace
